package com.laikan.reader.bookfriend.mactivity;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import com.laikan.reader.R;
import com.laikan.reader.bookfriend.fragment.AutherFactory;
import com.laikan.reader.bookfriend.utils.Constant;

/**
 * Created by admin on 2016/11/1.
 * 活动界面的第二种实现，使用Fragment
 */
public class ContentActivity extends BaseTitleActivity {

    public static final String PAGE_TYPE_FANS = "fans";//粉丝页
    public static final String PAGE_TYPE_FOCUS = "focus";//关注页
    public static final String PAGE_TYPE = "page_type";


    private FragmentManager mFm;

    @Override
    public void setTitleBar(boolean isAlpha) {
        super.setTitleBar(isAlpha);
        mBtRight.setVisibility(View.INVISIBLE);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_active_fragment;
    }

    @Override
    protected void assignViews() {
        super.assignViews();
        mFm = getSupportFragmentManager();
    }
    private String mUserId;

    public void setUserId(String userId) {
        mUserId = userId;
    }

    public String getUserId() {
        return mUserId;
    }

    @Override
    protected void initData() {

        Intent intent = getIntent();
        String pageType = intent.getStringExtra(PAGE_TYPE);
        setUserId(intent.getStringExtra(Constant.USER_ID));

        switch (pageType){
            case PAGE_TYPE_FANS:
                goToFansPage();
                break;
            case PAGE_TYPE_FOCUS:
                goToFocusPage();
                break;
            default:
                break;
        }
    }

    @Override
    protected void setListener() {

    }

    /**
     * 切换到关注页
     */
    private void goToFocusPage() {
        mTvTitle.setText("我关注的");
        FragmentTransaction transaction = mFm.beginTransaction();
        Fragment fragment = AutherFactory.createFragment(AutherFactory.TYPE_ATTENTION,"关注",getUserId());
        transaction.replace(R.id.content,fragment, PAGE_TYPE_FOCUS);
        transaction.commit();
    }

    /**
     * 切换到粉丝页
     */
    private void goToFansPage() {
        mTvTitle.setText("粉丝");
        FragmentTransaction transaction = mFm.beginTransaction();
        Fragment fragment = AutherFactory.createFragment(AutherFactory.TYPE_FUNS,"粉丝",getUserId());
        transaction.replace(R.id.content,fragment, PAGE_TYPE_FANS);
        transaction.commit();
    }

    @Override
    protected void onClickEvent(View view) {
        super.onClickEvent(view);
    }
}
